package studio7.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import studio7.exception.DAOException;
import studio7.negocio.AdministradorNegocio;

@WebServlet("/buscarSevXSala")
public class BuscarSevXSala extends HttpServlet{

	private static final long serialVersionUID = 1L;

	public void service(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException{
		final String log = "[ BuscarSevXSala.service ] ";
		System.out.println(log + "INICIO");
		AdministradorNegocio an = new AdministradorNegocio();
		HttpSession session = request.getSession(true);
		Object obj = session.getAttribute("cargar");
		try {
			//LLenado del combo Sala
			if(obj == null){
				session.setAttribute("arraySala", an.listarSala2());
				session.setAttribute("cargar", "listo");
			}else{//Busqueda de Servicios por Sala
				String idSala = request.getParameter("idSala");
				System.out.println(log+ "Datos seleccionados:");
				System.out.println(log + "idSala --> " + idSala);
				session.setAttribute("arrayBuscarSevXSala", an.buscarServicioxSala(Integer.parseInt(idSala)));
			}
		} catch (DAOException e) {
			System.out.println(log + "DAOException: " + e);
		}
		request.getRequestDispatcher("/buscarSevXSala.jsp").forward(request, resp);
		System.out.println(log + "FIN");
	}
}